Clear

/*

use "C:\Local\数据\ex2005 data.dta"

gen west = strmatch(location,"*重庆*")

replace west = 1 if strmatch(location,"*四川*")

replace west = 1 if strmatch(location,"*贵州*")

replace west = 1 if strmatch(location,"*云南*")

replace west = 1 if strmatch(location,"*西藏*")

replace west = 1 if strmatch(location,"*陕西*")

replace west = 1 if strmatch(location,"*甘肃*")

replace west = 1 if strmatch(location,"*青海*")

replace west = 1 if strmatch(location,"*宁夏*")

replace west = 1 if strmatch(location,"*新疆*")

replace west = 1 if strmatch(location,"*内蒙古*")

replace west = 1 if strmatch(location,"*广西*")

gen central = strmatch(location,"*山西*")

replace central = 1 if strmatch(location,"*吉林*")

replace central = 1 if strmatch(location,"*黑龙江*")

replace central = 1 if strmatch(location,"*安徽*")

replace central = 1 if strmatch(location,"*江西*")

replace central = 1 if strmatch(location,"*河南*")

replace central = 1 if strmatch(location,"*湖南*")

replace central = 1 if strmatch(location,"*湖北*")

gen east = strmatch(location,"*北京*")

replace east = 1 if strmatch(location,"*天津*")

replace east = 1 if strmatch(location,"*河北*")

replace east = 1 if strmatch(location,"*辽宁*")

replace east = 1 if strmatch(location,"*上海*")

replace east = 1 if strmatch(location,"*江苏*")

replace east = 1 if strmatch(location,"*浙江*")

replace east = 1 if strmatch(location,"*福建*")

replace east = 1 if strmatch(location,"*山东*")

replace east = 1 if strmatch(location,"*广东*")

replace east = 1 if strmatch(location,"*海南*")

replace east = 0 if west == 1 & east == 1

replace east = 1 if strmatch(location,"*温州*")

replace east = 1 if strmatch(location,"*青岛*")

replace east = 1 if strmatch(location,"*厦门*")

replace east = 1 if strmatch(location,"*珠海*")

replace east = 1 if strmatch(location,"*汕头*")

replace east = 1 if strmatch(location,"*深圳*")

replace east = 1 if strmatch(location,"*秦皇岛*")

replace east = 1 if strmatch(location,"*无锡*")

replace east = 1 if strmatch(location,"*淄博*")

replace east = 1 if strmatch(location,"*常州*")

replace east = 1 if strmatch(location,"*宁波*")

replace east = 1 if strmatch(location,"*南京*")

replace east = 1 if strmatch(location,"*苏州*")

replace east = 1 if strmatch(location,"*烟台*")

replace east = 1 if strmatch(location,"*广州*")

replace east = 1 if strmatch(location,"*石家庄*")

replace east = 1 if strmatch(location,"*沈阳*")

replace east = 1 if strmatch(location,"*威海*")

replace east = 1 if strmatch(location,"*鞍山*")

replace east = 1 if strmatch(location,"*佛山*")

replace east = 1 if strmatch(location,"*南通*")

replace east = 1 if strmatch(location,"*保定*")

replace east = 1 if strmatch(location,"*潍坊*")

replace east = 1 if strmatch(location,"*大连*")

replace east = 1 if strmatch(location,"*杭州*")

replace east = 1 if strmatch(location,"*连云港*")

replace east = 1 if strmatch(location,"*湛江*")

replace east = 1 if strmatch(location,"*镇江*")

replace east = 1 if strmatch(location,"*福州*")

replace east = 1 if strmatch(location,"*济南*")

replace east = 1 if strmatch(location,"*惠州*")

replace east = 1 if strmatch(location,"*中山*")

replace central = 1 if strmatch(location,"*芜湖*")

replace central = 1 if strmatch(location,"*合肥*")

replace central = 1 if strmatch(location,"*大庆*")

replace central = 1 if strmatch(location,"*长春*")

replace central = 1 if strmatch(location,"*郑州*")

replace central = 1 if strmatch(location,"*武汉*")

replace central = 1 if strmatch(location,"*洛阳*")

replace central = 1 if strmatch(location,"*哈尔滨*")

replace central = 1 if strmatch(location,"*太原*")

replace central = 1 if strmatch(location,"*长沙*")

replace central = 1 if strmatch(location,"*南昌*")

replace central = 1 if strmatch(location,"*株州*")

replace central = 1 if strmatch(location,"*襄樊*")

replace west = 1 if strmatch(location,"*西安*")

replace west = 1 if strmatch(location,"*成都*")

replace west = 1 if strmatch(location,"*昆明*")

replace west = 1 if strmatch(location,"*乌鲁木齐*")

replace west = 1 if strmatch(location,"*贵阳*")

replace west = 1 if strmatch(location,"*绵阳*")

replace west = 1 if strmatch(location,"*宝鸡*")

replace west = 1 if strmatch(location,"*兰州*")

replace west = 1 if strmatch(location,"*杨陵*")

replace west = 1 if strmatch(location,"*石河子*")

replace west = 1 if strmatch(location,"*桂林*")

replace west = 1 if strmatch(location,"*北海*")

replace west = 1 if strmatch(location,"*包头*")

replace west = 1 if strmatch(location,"*南宁*")

replace east = 0 if east == 1 & central == 1

gen east1 = strmatch(location,"*北京*")

replace east1 = 1 if strmatch(location,"*天津*")

replace east1 = 1 if strmatch(location,"*河北*")

replace east1 = 1 if strmatch(location,"*辽宁*")

replace east1 = 1 if strmatch(location,"*山东*")

gen east2 = strmatch(location,"*上海*")

replace east2 = 1 if strmatch(location,"*浙江*")

replace east2 = 1 if strmatch(location,"*江苏*")

gen east3 = strmatch(location,"*广东*")

replace east1 = 1 if strmatch(location,"*青岛*")

replace east1 = 1 if strmatch(location,"*秦皇岛*")

replace east1 = 1 if strmatch(location,"*淄博*")

replace east1 = 1 if strmatch(location,"*烟台*")

replace east1 = 1 if strmatch(location,"*石家庄*")

replace east1 = 1 if strmatch(location,"*沈阳*")

replace east1 = 1 if strmatch(location,"*威海*")

replace east1 = 1 if strmatch(location,"*鞍山*")

replace east1 = 1 if strmatch(location,"*保定*")

replace east1 = 1 if strmatch(location,"*潍坊*")

replace east1 = 1 if strmatch(location,"*大连*")

replace east1 = 1 if strmatch(location,"*济南*")

replace east2 = 1 if strmatch(location,"*无锡*")

replace east2 = 1 if strmatch(location,"*温州*")

replace east2 = 1 if strmatch(location,"*常州*")

replace east2 = 1 if strmatch(location,"*宁波*")

replace east2 = 1 if strmatch(location,"*南京*")

replace east2 = 1 if strmatch(location,"*苏州*")

replace east2 = 1 if strmatch(location,"*南通*")

replace east2 = 1 if strmatch(location,"*杭州*")

replace east2 = 1 if strmatch(location,"*连云港*")

replace east2 = 1 if strmatch(location,"*镇江*")

replace east3 = 1 if strmatch(location,"*惠州*")

replace east3 = 1 if strmatch(location,"*中山*")

replace east3 = 1 if strmatch(location,"*湛江*")

replace east3 = 1 if strmatch(location,"*珠海*")

replace east3 = 1 if strmatch(location,"*汕头*")

replace east3 = 1 if strmatch(location,"*深圳*")

replace east3 = 1 if strmatch(location,"*广州*")

replace east3 = 1 if strmatch(location,"*佛山*")

gen region = "西部" if west == 1

replace region = "东部" if east == 1

replace region = "中部" if central == 1

gen subregion = "环渤海湾经济圈" if east1 == 1

replace subregion = "长江三角洲经济区" if east2 == 1

replace subregion = "珠江三角洲经济区" if east3 == 1

bys region: egen t_r = total(value)
  
bys region: egen i_r = total(value) if trader == 1
  
bys region: egen d_r = total(value) if trader == 0

bys subregion: egen st_r = total(value)
  
bys subregion: egen si_r = total(value) if trader == 1
  
bys subregion: egen sd_r = total(value) if trader == 0

format t_r %20.0fc
  
format i_r %20.0fc
  
format d_r %20.0fc

keep if east == 1

save "C:\Local\数据\Table 5\table 5 data - east.dta"

save "C:\Local\数据\Table 5\table 5 data - east-total.dta"

keep if east1 == 1

save "C:\Local\数据\Table 5\table 5 data - east1.dta"

keep if east2 == 1

save "C:\Local\数据\Table 5\table 5 data - east2.dta"

keep if east3 == 1

save "C:\Local\数据\Table 5\table 5 data - east3.dta"

keep if central == 1

save "C:\Local\数据\Table 5\table 5 data - central.dta"

keep if west == 1

save "C:\Local\数据\Table 5\table 5 data - west.dta"

Use "C:\Local\数据\Table 5\table 5 data - east/central/west/east1/east2/east3.dta", clear

egen ownership = group(firmtype)

egen country = group(partner)

egen id = group(hs8) 
egen cid = group(hs8 country)
egen ocid = group(hs8 country ownership)
egen oid = group(ownership hs8)

//ownership 1-Chinese foreign cooperative enterprises中外合作企业/2-sino-foreign equity joint venture中外合资企业
//3-Other 其它/4-state-owned enterprises (SOE)国有企业/5-Wholly Foreign-owned Enterprise( WFOE)
//外商独资企业/6-private business私营企业/7-collective enterprise集体企业

gen o2=.
    replace o2 = 1 if ownership ==4
	replace o2 = 2 if ownership ==1|ownership ==2|ownership ==5
	replace o2 = 3 if ownership ==6|ownership ==7|ownership ==3

g p = value/quantity
    drop if p==.
    bys o2 hs8: egen p97 = pctile(p), p(95)
	bys o2 hs8: egen p3 = pctile(p), p(5)
	drop if p>p97
	drop if p<p3
		
	g lp = log(p)

	bys firmid: egen totv = sum(value)
	g ltotv1 = log(totv)
	g ltotv2 = ltotv1^2
	g ltotv3 = ltotv1^3
	g ltotv4 = ltotv1^4
	
drop productcode unit firmid zip firm location firmtype partner tradetype value ///
quantity price year t i d hs2 sector region subregion t_r i_r d_r st_r si_r sd_r ///
ownership country id cid oid o2 p p97 p3 west central east east1 east2 east3 totv

save "C:\Local\数据\Table 5\table 5 data - east/central/west/east1/east2/east3.dta", replace
	
*/


/*

Use "C:\Local\数据\ex2000/2001/2002/2003/2004 data.dta", clear

egen ownership = group(firmtype)

egen country = group(partner)

egen id = group(hs8) 
egen cid = group(hs8 country)
egen ocid = group(hs8 country ownership)
egen oid = group(ownership hs8)

//ownership 1-Chinese foreign cooperative enterprises中外合作企业/2-sino-foreign equity joint venture中外合资企业
//3-Other 其它/4-state-owned enterprises (SOE)国有企业/5-Wholly Foreign-owned Enterprise( WFOE)
//外商独资企业/6-private business私营企业/7-collective enterprise集体企业

gen o2=.
    replace o2 = 1 if ownership ==4
	replace o2 = 2 if ownership ==1|ownership ==2|ownership ==5
	replace o2 = 3 if ownership ==6|ownership ==7|ownership ==3

g p = value/quantity
    drop if p==.
    bys o2 hs8: egen p97 = pctile(p), p(95)
	bys o2 hs8: egen p3 = pctile(p), p(5)
	drop if p>p97
	drop if p<p3
		
	g lp = log(p)

	bys firmid: egen totv = sum(value)
	g ltotv1 = log(totv)
	g ltotv2 = ltotv1^2
	g ltotv3 = ltotv1^3
	g ltotv4 = ltotv1^4

drop drop firmid firm zip location firmtype partner tradetype value quantity price ///
year ownership country id cid oid o2 p p97 p3 totv unit

save "C:\Local\数据\Table 5\table 5 data - 2000/2001/2002/2003/2004.dta"
	
*/

/*

///Panel 2000-2005

///Append 2000-2005	

use "C:\Local\数据\Table 2\table 2 data.dta"

append using "C:\Local\数据\Table 5\table 5 data - 2004.dta"

append using "C:\Local\数据\Table 5\table 5 data - 2003.dta"

append using "C:\Local\数据\Table 5\table 5 data - 2002.dta"

append using "C:\Local\数据\Table 5\table 5 data - 2001.dta"

append using "C:\Local\数据\Table 5\table 5 data - 2000.dta"

save "C:\Local\数据\Table 5\table 5 data - panel.dta"

*/


/// Table 5 Panel A

use "C:\Local\数据\Table 5\table 5 data - east/central/west/2000/2001/2002/2003/2004.dta", clear

areg lp trader ltotv*, a(ocid) cluster(hs8)

/// Table 5 Panel B

use "C:\Local\数据\Table 5\table 5 data - east1/east2/east3.dta", clear

areg lp trader ltotv*, a(ocid) cluster(hs8)

use "C:\Local\数据\Table 5\table 5 data - panel.dta", clear

xi: areg lp trader ltotv* i.year, a(ocid) cluster(hs8)		
			
